package com.example.result.dao.api

import android.content.Context
import android.util.Log
import androidx.preference.PreferenceManager
import com.example.result.dao.vo.DaoDatas
import com.example.result.preference.Config
import okhttp3.HttpUrl
import okhttp3.OkHttpClient
import retrofit2.Call
import retrofit2.Retrofit
import retrofit2.converter.gson.GsonConverterFactory
import retrofit2.http.GET
import retrofit2.http.Query

interface DaoApi {
    @GET("/android/dao/data.json")
    fun getData(@Query("id") id: Int = 0): Call<DaoDatas>

    companion object {

        fun create(context: Context): DaoApi = create(Config.getUrl(context))
        fun create(httpUrl: HttpUrl): DaoApi {
            val logger = HttpLoggingInterceptor(object : Logger {
                override fun log(message: String?) {
                    Log.d("DaoApi", "$message")
                }

            })
            logger.level = HttpLoggingInterceptor.Level.BASIC

            val client = OkHttpClient.Builder()
                .addInterceptor(logger)
                .build()
            return Retrofit.Builder()
                .baseUrl(httpUrl)
                .client(client)
                .addConverterFactory(GsonConverterFactory.create())
                .build()
                .create(DaoApi::class.java)
        }
    }
}

enum class PullState {
    SUCCESS,
    FAILURE

}